#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int N, R;
	while (cin >> N >> R)
	{
		int arr[1001];
		int i = 0;
		int t = 0;
		t = N;
		if (N < 0)
		{
			t = -N;
		}
		while (t)
		{
			arr[i++] = t % R;
			t /= R;
		}
		i--;
		if (N < 0) {
			cout << "-";
		}
		for (; i >= 0; i--)
		{
			if (arr[i] < 10) {
				cout << arr[i];
			}
			else if (arr[i] == 10) {
				cout << "A";
			}
			else if (arr[i] == 11) {
				cout << "B";
			}
			else if (arr[i] == 12) {
				cout << "C";
			}
			else if (arr[i] == 13) {
				cout << "D";
			}
			else if (arr[i] == 14) {
				cout << "E";
			}
			else if (arr[i] == 15) {
				cout << "F";
			}
		}
		cout << endl;
	}
	return 0;
}